Reads strings from a sequential file into a variable.
順編成ファイルから文字列を読み取り、変数に格納します。
Line Input #FileNumber As Integer, Var As String
Line Input #FileNumber As Integer, Var As String
FileNumber: Number of the file that contains the data that you want to read. The file must have been opened in advance with the Open statement using the key word INPUT.
FileNumber: 読み取るデータを含むファイルの番号。 読み取るファイルは、Open ステートメントに INPUT キーワードを指定して、事前に開いておく必要があります。
var: The name of the variable that stores the result.
var: 戻り値を格納する変数の名前。
With the Line Input# statement, you can read strings from an open file into a variable. String variables are read line-by-line up to the first carriage return (Asc=13) or linefeed (Asc=10). Line end marks are not included in the resulting string.
Line Input# ステートメントは、オープン済みのファイルから文字列を読み取って、その値を変数に格納します。文字列は、次に来るキャリッジリターン (ASC=13) かラインフィード (ASC=10) までのデータが、1 行ごとに読み取られます。行末の記号は読み取られません。
Sub ExampleWorkWithAFile
Sub ExampleWorkWithAFile
Dim iNumber As Integer
Dim iNumber As Integer
Dim sLine As String
Dim sLine As String
Dim aFile As String
Dim aFile As String
Dim sMsg as String
Dim sMsg as String
aFile = "c:\data.txt"
aFile = "c:\data.txt"
iNumber = Freefile
iNumber = Freefile
Open aFile For Output As #iNumber
Open aFile For Output As #iNumber
Print #iNumber, "This is a line of text"
Print #iNumber, "This is a line of text"
Print #iNumber, "This is another line of text"
Print #iNumber, "This is another line of text"
Close #iNumber
Close #iNumber
iNumber = Freefile
iNumber = Freefile
Open aFile For Input As iNumber
Open aFile For Input As iNumber
While not eof(iNumber)
While not eof(iNumber)
Line Input #iNumber, sLine
Line Input #iNumber, sLine
If sLine <>"" then
If sLine <>"" then
sMsg = sMsg & sLine & chr(13)
sMsg = sMsg & sLine & chr(13)
end if
end if
wend
Wend
Close #iNumber
Close #iNumber
Msgbox sMsg
Msgbox sMsg
End Sub
End Sub